{use master_page('admin/v_master')} 
  
{block content}
<?php 
$cu_group = $this->usergroup_manager->get($this->current_user()->usergroup_id);  
?>
<script>
$(document).ready(function(){
	$('#type').change(function(){
		var v = $(this).val(); 
		<?
		$get_type = array_remove($_GET, 'type');
		$get_params = Array();
		foreach($_GET as $k=>$v)
		{
			$get_params[] = "$k=$v";
		}
		$get_params_str = implode('&',$get_params);
		?>
		var url = '<?=_U("menu/index?")?><?=$get_params_str?>&type=' + v;
		//alert(url);
		//window.open(url);
		window.location.href = url ;  
	}) ;

	$("#chkall").click(function(){
		var checked = $(this).attr("checked");
		$(".datatable tbody input[type=checkbox]").attr("checked",checked) ;  
	}) ; 
	
})
</script>
<?php
$ci = & get_instance();
require_once(APPPATH."views/".$ci->template."/admin_helper.php"); 
$menu_infos = menus();
$menu_info = $menu_infos[$_GET['name']];
//print_r($menu_info);exit;
$ci->menu_info = $menu_info;
$ci->cu_group = $cu_group ; 
$select_html = "<select id='parent_id' class='bind'><option value='0'>顶层</option>";  
$ci->select_html = $select_html;

function bl_article_class($items,$level=1)
{
	$ci = & get_instance();
	$cu_group = $ci->cu_group ;   
	// $menu_infos = menus();
	$menu_info = $ci->menu_info;  
	if($level>=$menu_info->max_level) return;
	foreach($items as $item):
	$pad = "";
	if($level>=1)
	{
		for($i=0;$i<$level-1;$i++)
		{
			$pad = $pad . "&nbsp;&nbsp;";
	}
	$pad = $pad."└";
	}
	if($level == 0){
		$pad="";
	}
	if(!empty($_GET['id'])):
	if($item->id!=$_GET['id']):
		if(($level+1)<$menu_info->max_level){$ci->select_html .= "<option value='$item->id'>$pad$item->title</option>";};
	endif;
	else:
		if(($level+1)<$menu_info->max_level){
			$ci->select_html .= "<option value='$item->id'>$pad$item->title</option>";
		};
	endif;
	?>
	<tr>
		<td style="width:31px;">
			<input type="checkbox" value="<?php echo $item->id;?>" name="ids[]">
		</td>
		<td align="center">
			<span style="width:59px" class="hotspot">
				<input type="text" name="listorder[<?php echo $item->id?>]" value="<?php echo $item->order;?>" class="input_c">
			</span>
		</td>
		<!--td align="center">{item->id}</td--> 
		<td style="text-align:left;padding-left:<?=$level*10?>px;" align="left" >
			└<?=$item->title?>
			<?if(($level+1)<$menu_info->max_level):?> 
			<?endif?> 
		</td> 
		<td align="center"><?=get_menu_type_name($item->type)?></td>
		<td align="center"><?=$item->target_window=='_self'?'本窗口':($item->target_window=='_blank'?'新窗口':$item->target_window)?></td>  
		<td>
			<?php if($cu_group->permission("menu","edit")):?>	
			<a  class="edit" onmouseover="tooltip.show('编辑');" onmouseout="tooltip.hide();" href="<?=_U('menu/edit?name='.$_GET['name'].'&id=')?>{item->id}">
			</a>
			<?php endif;?>
			<?php if($cu_group->permission("menu","edit")):?>
			<?php if($level<$menu_info->max_level-1):?>
			<a  class="a_add_content" onmouseover="tooltip.show('添加子栏目');" onmouseout="tooltip.hide();" href="<?=_U("menu/edit?name=".$_GET['name']."&parent_id=$item->id")?>">
			</a>
			<?php endif;?>
			<?php endif;?>
			<?php if($cu_group->permission("menu","del")):?>
			<a class="delete" onmouseover="tooltip.show('删除');" onmouseout="tooltip.hide();" onclick="javascript:return confirm('确认删除');" href="<?=_U('menu/del?id=')?>{item->id}">
			</a>
			<?php endif;?>
		</td>
	</tr>
	<?if(sizeof($item->items)>0){bl_article_class($item->items,$level+1);}?>
	<?php endforeach;?>
<?}?> 
<style>
.description{padding:6px;border:1px solid #afafaf;background:#fafafa} 
.main{margin:0px;padding:0px}
</style>
<form id = 'form1' action = '<?=$_SERVER['REQUEST_URI']?>' method='post'>
<div class="blank20" style="height:10px;"></div>
<?php if($cu_group->permission("menu","edit")):?>
<div style="padding-left:10px;">
		<input style="width:132px;height:38px;line-height:38px;color:white;background:url(images/btn_03.gif) left top no-repeat;border:none; text-align:center;
 			 cursor: pointer;" class="btn_c" type="button" value=" 添加栏目 " 
 			 onclick="javascript:window.location.href='<?php echo _U("menu/edit?name=".$this->input->get("name"));?>'">
</div>
<?php endif;?>
<div class="blank5" style="height:10px;"></div>
<div id="tagscontent" class="right_box">
	<table class="datatable" >
		<thead>
		<tr>
			
			<!--th><?=lang('menu_item_id')?></th-->
			<th >
				<input title="点击可全选本页的所有项目" type="checkbox" id="chkall">
			</th> 
			<th >排序</th>
			<!--th><?=lang('menu_item_id')?></th-->
			<th ><?=lang('menu_item_name')?></th>
			<th ><?=lang('menu_item_type')?></th>
			<th ><?=lang('menu_item_target_window')?></th>
			<th><!--isnav-->操作</th>
		</tr></thead>
		<tbody>
			<?php foreach($items as $item):
			if(!empty($_GET['id'])):
			if($item->id!=$_GET['id']):
			$ci->select_html .= "<option value='$item->id'>$item->title</option>";
			endif;
			else:
			$ci->select_html .= "<option value='$item->id'>$item->title</option>";
			endif;
			?>
			<tr> 
				<td style="width:31px;">
					<input type="checkbox" value="<?php echo $item->id;?>"  name="ids[]">
				</td>
				<td align="center">
					<span style="width:59px" class="hotspot">
						<input type="text" name="listorder[<?php echo $item->id?>]" value="<?php echo $item->order;?>" class="input_c">
					</span>
				</td>
				<!--td align="center">{item->id}</td-->  
				<td style="text-align:left" align="left"><?=$item->title?> 
				<?if($menu_info->max_level>1):?> 
				<?endif;?>
				</td> 
				<td align="center"><?=get_menu_type_name($item->type)?></td>
				<td align="center"><?=($item->target_window=='_self')?'本窗口':($item->target_window=='_blank'?'新窗口':$item->target_window)?></td>
				<td>
					<?php if($cu_group->permission("menu","edit")):?>
					<a  class="edit" onmouseover="tooltip.show('编辑');" onmouseout="tooltip.hide();" href="<?=_U('menu/edit?name='.$_GET['name'].'&id=')?>{item->id}">
					</a>
					<?php endif;?>
					<?php if($cu_group->permission("menu","edit")):?>
					<?php if($menu_info->max_level>1):?>
					<a  class="a_add_content" onmouseover="tooltip.show('添加子栏目');" onmouseout="tooltip.hide();" href="<?=_U("menu/edit?name=".$_GET['name']."&parent_id=$item->id")?>">
					</a>
					<?php endif;?>
					<?php endif;?>
					<?php if($cu_group->permission("menu","del")):?>
					<a class="delete" onmouseover="tooltip.show('删除');" onmouseout="tooltip.hide();" onclick="javascript:return confirm('确认删除');" href="<?=_U('menu/del?id=')?>{item->id}">
					</a>
					<?php endif;?>
				</td>
			</tr>
			<?if(sizeof($item->items)>0){bl_article_class($item->items,1);}?>
			<?php endforeach;$ci->select_html.="</select>"?> 
		</tbody>
	</table>
</div>

<script>
$(document).ready(function(){
	$('#btn_delete').click(function(){
		var frm = $("#form1");
		frm.attr('action','<?php echo _U("menu/del");?>'); 
		frm.submit();
	});
	$('#btn_order').click(function(){
		var frm = $("#form1");
		frm.attr('action','<?php echo _U("menu/order");?>'); 
		frm.submit();
	});
	
	$('#btn_moveto').click(function(){
		var frm = $("#form1");
		var id = $("#parent_id").val();
		if(id!="")
		{
			var url = '<?php echo _U("menu/moveto/");?>' + id;
			frm.attr('action',url); 
			frm.submit();
		}
		else
		{
			alert("请选择移动到的菜单") ;      
		}
	});
});
</script>
<div class="blank10" style="height:10px"></div>
<input type="hidden" name="batch" value="">
<?php if($cu_group->permission("menu","del")):?>
<input class="btn_d" type="button" value=" 删除 " id="btn_delete">
<?php endif;?>
<?php if($cu_group->permission("menu","order")):?>
<input class="btn_d" type="button" value=" 排序 " id="btn_order">
<?php endif;?>
<?php if($cu_group->permission("menu","moveto")):?>
<input class="btn_e" type="button" value=" 移动到 " id="btn_moveto" >
	<?php echo $ci->select_html;?>
<?php endif;?>
<!--input class="btn_e" type="button" value=" 移动到 " name="btn_moveto" onclick="if(getSelect(this.form) &amp;&amp; confirm('确实要移动ID为('+getSelect(this.form)+')的栏目吗?')){this.form.action='/index.php?case=table&amp;act=batch&amp;table=category&amp;admin_dir=admin&amp;site=default&amp;page=1'; this.form.batch.value='move'; this.form.submit();}">
<select id="catid" name="catid">
	<option value="0" selected="">请选择...</option>
	<option value="26">公司简介</option>
	<option value="33">&nbsp;&nbsp;公司荣誉</option>
	<option value="34">&nbsp;&nbsp;施工现场</option>
	<option value="34">&nbsp;&nbsp;新闻动态</option>
	<option value="34">&nbsp;&nbsp;人才招聘</option>
	<option value="34">&nbsp;&nbsp;联系我们</option>
</select-->
<div class="blank10" style="height:0px"></div>
	
</form>
{end}  